<!--
  作者：xhr
  时间：2022年09月21日 10:10:37
-->
<template>
    <div style="padding: 10px">
        <div style="margin-left: 40px; margin: 30px 0; color: dodgerblue; font-size:28px ;">{{ exams.find(v => v.id === this.eid) ? exams.find(v =>
                        v.id === this.eid).name : '' }}&nbsp;&nbsp; {{ users.find(v => v.id === this.id) ? users.find(v =>
                        v.id === this.id).username : '' }}</div>
        <el-table :data="papers" border stripe>
            <el-table-column sortable prop="id" label="题目ID"></el-table-column>
            <el-table-column prop="name" label="题目名称"></el-table-column>
            <el-table-column prop="type" label="题目类型">
                <template v-slot="scope">
                    <span v-if="scope.row.type == 1">选择题</span>
                    <span v-if="scope.row.type == 2">判断题</span>
                    <span v-if="scope.row.type == 3">简答题</span>
                </template>
            </el-table-column>
            <el-table-column prop="a" label="A选项"></el-table-column>
            <el-table-column prop="b" label="B选项"></el-table-column>
            <el-table-column prop="c" label="C选项"></el-table-column>
            <el-table-column prop="d" label="D选项"></el-table-column>
            <el-table-column prop="score" label="标准分数"></el-table-column>
            <el-table-column prop="answear" label="标准答案"></el-table-column>
            <el-table-column prop="studentAnswear" label="学生答案"></el-table-column>
            <el-table-column prop="detail" label="解析"></el-table-column>
            <el-table-column prop="studentScore" label="得分">
                <template v-slot="scope">
                    <el-input v-model="scope.row.studentScore"></el-input>
                </template>
            </el-table-column>

        </el-table>
        <div style="margin: 10px 0">
            <el-button type="primary" @click="submitHandle">提交</el-button>
            <el-button type="primary" @click="$router.push('/studentPaper')">返回</el-button>
        </div>
    </div>
</template>

<script>
import request from "@/utils/request";
export default {
    name: 'handlePaper',
    data() {
        return {
            sp: this.$route.query.sp,
            papers: [],
            users: [],
            exams: [],
            id:null,
            eid:null,
        }
    },
    computed: {},
    watch: {},
    created() {
        request.get("/user").then((res) => {
            this.users = res.data;
        });
        request.get("/exam").then((res) => {
            this.exams = res.data;
        });
        
        request.get("/studentPaper/" + this.sp).then((res) => {
            this.id=res.data.userId;
            this.eid=res.data.examId;
            this.papers = JSON.parse(res.data.paper);
            if (this.papers && this.papers.length) {
                this.papers.forEach(item => {
                    if (item.answear == item.studentAnswear) {
                        item.studentScore = item.score;
                    }
                });
            }
        });
    },
    mounted() { },
    methods: {
        submitHandle() {
            let sum = 0;
            this.papers.forEach(item => {
                if (item.studentScore == null) {
                    item.studentScore = 0;
                }
                sum += parseInt(item.studentScore) ;
            });
            request.post("/studentPaper", { id: this.sp, score: sum ,state:'已评阅'}).then((res) => {
                if (res.code === "0") {
                    this.$message({
                        type: "success",
                        message: "打分成功",
                    });
                    this.$router.push('/studentPaper');
                }
            });
        },
    }
}
</script>

<style scoped>

</style>
